/************************************************************************/
/* Summary:		The implementation of the table.h 
/* Creator:		Created by BBzjdrk
/* Date:		2010-4-29
/* RevisedBy:	//
/************************************************************************/

#ifndef __BTREE_H__
#define __BTREE_H__


#define M 4 
#define KEY_NUM (2 * M - 1)


#include "system_data.h"
#include "utility.h"


struct btree_t* bnode_factory_create();

void show_keys_in_btree(struct btree_t* p, int i_depth);


/************************************************************************/
/* Summary:	Insert into this node,  this node is not full
/* Return:	The node it has inserted the tuple
/* param0:	The subroot
/* param1:	The tuple to be inserted
/* param2:	The size of the p_tuple's data field
/* Author:	NextLine
/* Date:		2010-4-27
/* Revise:	BBzjdrk 2010-4-23,24; Shiwen 2010-4-26 
/************************************************************************/
char btree_insert(struct btree_t **btree, struct tuple_t* p_tuple);

/************************************************************************/
/* Summary:	Delete a tuple from the p_btree node.
/* Return:	1 If succeed, 0 otherwise.
/* param0:	The subroot node from which the tuple will be deleted
/* param1:	The pointer of the tuple
/* Author:	NextLine
/* Date:		2010-4-23
/* Revise:	BBzjdrk 2010-4-26; Shiwen 2010-4-27
/************************************************************************/
char btree_delete(struct btree_t **p_btree, struct tuple_t* p_tuple, int* p_affected_row_num);

/************************************************************************/
/* Summary:	Search the specified tuple in the btree node
/* Return:	The pointer of the tuple we are finding, NULL if it does not exist.
/* param0:	The node from where we are finding
/* param1:	Tuple we are finding.
/* param2:	The index of the tuple array where the tuple appears
/* Author:	NextLine
/* Date:		2010-4-23
/* Revise:	BBzjdrk 2010-4-26
/************************************************************************/
struct btree_t* btree_search(struct btree_t *btree, struct tuple_t* p_tuple, int *index);


#endif /* __BTREE_H__ */
